//
//  MessageViewController.m
//  MiaoTu
//
//  Created by dllo on 16/9/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MessageViewController.h"
#import "MessageTableCell.h"
#import "SysMsgViewController.h"

#define kMessageTableCell @"MessageTableCellIdentifier"

@interface MessageViewController () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray<NSDictionary *> *dicArray;
@end

@implementation MessageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createTableView];
    [self createData];
}

- (void)createTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MessageTableCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kMessageTableCell];
    _tableView.rowHeight = 86;
}

- (void)createData {
    self.dicArray = @[@{@"pic":@"systemMessage", @"title":@"系统消息", @"color":[UIColor colorWithRed:0.933 green:0.757 blue:0.039 alpha:1.000]},
                      @{@"pic":@"likeRemind", @"title":@"喜欢提醒", @"color":[UIColor colorWithRed:0.906 green:0.243 blue:0.024 alpha:1.000]},
                      @{@"pic":@"enrollRemind", @"title":@"报名提醒", @"color":[UIColor colorWithRed:0.918 green:0.443 blue:0.094 alpha:1.000]},
                      @{@"pic":@"chat", @"title":@"聊天", @"color":[UIColor colorWithRed:0.227 green:0.498 blue:0.929 alpha:1.000]},
                      @{@"pic":@"concernRemind", @"title":@"关注提醒", @"color":[UIColor colorWithRed:0.294 green:0.882 blue:0.016 alpha:1.000]},
                      @{@"pic":@"commentRemind", @"title":@"评论提醒", @"color":[UIColor colorWithRed:0.718 green:0.141 blue:0.902 alpha:1.000]},
                      @{@"pic":@"service", @"title":@"客服", @"color":[UIColor colorWithRed:0.278 green:0.690 blue:0.906 alpha:1.000]}
                      ];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dicArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MessageTableCell *cell = [tableView dequeueReusableCellWithIdentifier:kMessageTableCell forIndexPath:indexPath];
    NSDictionary *dic = _dicArray[indexPath.row];
    cell.picImage.image = [UIImage imageNamed:dic[@"pic"]];
    cell.backView.backgroundColor = dic[@"color"];
    cell.titleLabel.text = dic[@"title"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        SysMsgViewController *sysMessageVC = [SysMsgViewController new];
        [self.navigationController pushViewController:sysMessageVC animated:YES];
    }
    NSLog(@"%@", _dicArray[indexPath.row]);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
